import { Configuration, OpenAIApi } from "openai";

let configuration = new Configuration({
  apiKey: "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", // 随机生成,非真实key
});

// Delete it ， 解决控制台User-Agent报错
delete configuration.baseOptions.headers["User-Agent"];

const openAI = new OpenAIApi(configuration);

export const chatWithChatGPT = (str: string) => {
  return new Promise(async (resolve) => {
    const res = await openAI.createChatCompletion({
      model: "gpt-3.5-turbo",
      messages: [{ role: "user", content: str }],
    });
    resolve(res);
  });
};
